<?php

/**
 * This is the model class for table "tb_periodo".
 *
 * The followings are the available columns in table 'tb_periodo':
 * @property integer $id
 * @property string $descripcion
 * @property string $fecha
 * @property integer $tb_cuentas_id
 * @property double $saldoant
 * @property double $saldoact
 *
 * The followings are the available model relations:
 * @property TbCapital[] $tbCapitals
 * @property TbPagos[] $tbPagoses
 * @property TbCuentas $tbCuentas
 */
class TbPeriodo extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return TbPeriodo the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tb_periodo';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('descripcion, fecha, tb_cuentas_id', 'required'),
			array('tb_cuentas_id', 'numerical', 'integerOnly'=>true),
			array('saldoant, saldoact', 'numerical'),
			array('descripcion', 'length', 'max'=>10),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, descripcion, fecha, tb_cuentas_id, saldoant, saldoact', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'tbCapitals' => array(self::HAS_MANY, 'TbCapital', 'tb_periodo_id'),
			'tbPagoses' => array(self::HAS_MANY, 'TbPagos', 'tb_periodo_id'),
			'tbCuentas' => array(self::BELONGS_TO, 'TbCuentas', 'tb_cuentas_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'descripcion' => 'Descripcion',
			'fecha' => 'Fecha',
			'tb_cuentas_id' => 'Tb Cuentas',
			'saldoant' => 'Saldoant',
			'saldoact' => 'Saldoact',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('descripcion',$this->descripcion,true);
		$criteria->compare('fecha',$this->fecha,true);
		$criteria->compare('tb_cuentas_id',$this->tb_cuentas_id);
		$criteria->compare('saldoant',$this->saldoant);
		$criteria->compare('saldoact',$this->saldoact);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}